package com.qf.service.impl;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.qf.entity.Product;
import com.qf.entity.request.ProductRequest;
import com.qf.entity.response.ProductResponse;
import com.qf.mapper.ProductMapper;
import com.qf.service.IProductService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;

/**
 * <p>
 * 商品表 服务实现类
 * </p>
 *
 * @author chen
 * @since 2021-03-18
 */
@Service
public class ProductServiceImpl extends ServiceImpl<ProductMapper, Product> implements IProductService {

    @Resource
    private ProductMapper productMapper;

    @Override
    public Page<ProductResponse> findListForPage(ProductRequest request) {
        IPage<ProductResponse> productIPage = new Page<>(request.getPage(),request.getSize());
        return productMapper.selectListForPage(productIPage,request);
    }

    @Override
    public void upOrDown(Long id) {
        Product product = productMapper.selectById(id);
        if(product.getProductStatus() == 0){
            product.setProductStatus(1);
        }else {
            product.setProductStatus(0);
        }
        productMapper.updateById(product);
    }
}
